package ratkit.repast;

import java.lang.reflect.Constructor;

import repast.simphony.context.DefaultContext;

/**
 * Test environment for test agents.
 */
public class RepastTestEnvironment extends DefaultContext<Object> {

	/**
	 * initializes test environment with given name
	 * 
	 * @param name
	 *            name of the environment.
	 */
	public RepastTestEnvironment(Object name) {
		super(name);
	}

	/**
	 * Creates an instance of test agent the given class name.
	 * 
	 * @param className
	 *            class name of the tester agent.
	 */
	public void createTestAgent(String className) {
		try {
			Class<?> cls = Class.forName(className);
			Constructor<?> constructor = cls.getConstructor();
			Object testAgent = constructor.newInstance();
			this.add(testAgent);
		} catch (Throwable e) {
			System.err
					.println("Error while initializing the Test agent instance.");
			e.printStackTrace();
		}
	}
}
